from tools_algorithm import *


class Solution:
    def maxSelectedElements(self, nums: List[int]) -> int:
        f = [[0] * 2 for _ in range(222)]
        nums.sort()
        ans = 0
        for num in nums:
            if f[num][0] > 0 or f[num][1] > 0 and f[num + 1][1] == 0:
                f[num + 1][1] = max(f[num][0], f[num][1]) + 1
                ans = max(ans, f[num + 1][1])
            else:
                f[num][0] = max(f[num - 1][0], f[num - 1][1]) + 1
                f[num + 1][1] = f[num][0]
                ans = max(ans, f[num][0])
        print(nums)
        print(f)
        return ans


s = Solution()
print(s.maxSelectedElements([2, 1, 5, 1, 1]))
print(s.maxSelectedElements([8, 10, 6, 12, 9, 12, 2, 3, 13, 19, 11, 18, 10, 16]))
